// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import AudioManage, {soundList} from "../../framework/AudioManage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class endlessScene2 extends cc.Component {

    @property(cc.Node)
    showList : cc.Node[] = [];

    @property(cc.Node)
    btnList : cc.Node[] = [];

    @property(cc.Node)
    bottleNode : cc.Node = null;

    @property(cc.Label)
    showLabel : cc.Label[] = [];

    @property(cc.Node)
    fontNode : cc.Node = null;

    @property({type : cc.Component.EventHandler})
    toolEvent : cc.Component.EventHandler[] = [];

    clickTimes = 0;


    onLoad(){
        this.fontAction();
        AudioManage.playSFX(soundList.colour);
    }

    fontAction(){
        cc.tween(this.fontNode).to(0.2,{
            scale : 1.5
        }).call(()=>{
            cc.tween(this.fontNode).delay(2).call(()=>{
                cc.tween(this.fontNode).to(0.2,{
                    scale : 0
                }).start();
            }).start();
        }).start();
    }

    btnClick(event,data){
        this.clickTimes++;
        this.showList[parseInt(data) - 1 ].active = true;
        event.target.parent.active = false;
        if(this.clickTimes < 4){
            this.showLabel[0].string = "找到不同的点:" + (5 - this.clickTimes);
            this.showLabel[1].string = "找到不同的点:" + (5 - this.clickTimes);
        }else if(this.clickTimes == 4){
            this.showLabel[0].string = "找到不同的点:" + (5 - this.clickTimes);
            this.showLabel[1].string = "找到不同的点:2";
            this.btnList[4].active = true;
        }else{
            this.showLabel[0].string = "没有不同了";
            this.showLabel[1].string = "没有不同了";
        }

        if(this.clickTimes >= 5){
            cc.Component.EventHandler.emitEvents(this.toolEvent, []);
        }
    }

    showAppBtn(event,data){
        event[0].active = false;
        this.btnList[2].active = true;
    }

    showBottle(event,data) {
        event[0].active = false;
        this.bottleNode.active = true;
        this.btnList[3].active = true;
    }


    // update (dt) {}
}
